package backstage.app.service.impl.util;

import java.time.LocalDateTime;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import backstage.app.entity.NoConstionParent;
import backstage.app.mapper.NoConstionParentMapper;
import backstage.app.respont.RespontDateJson;

@Component
public class NoConstionParentUtil {

	@Autowired
	private NoConstionParentMapper noConstionParentMapper;
	
	public RespontDateJson<?>inser(
			//标题信息
			String content,String height,String width,String abduction,
			String fingerSpan,String singForward,String roundTrip,String courtSprint,String restrtedArea,String klingWing,
			String verticalJump,String continJump){
		
		if(content==null) {
			return RespontDateJson.fuall(content,"类型名称不能为空");
		}
		
		QueryWrapper<NoConstionParent>queryWrapper=new QueryWrapper<NoConstionParent>();
		queryWrapper.eq("content", content);
		
		NoConstionParent constionParent=noConstionParentMapper.selectOne(queryWrapper);
		if(constionParent!=null) {
			//已经有了该类型了
			return RespontDateJson.fuall(constionParent, "数据库中已经存在了该类型名称，请更换名称");
		} 
		
		NoConstionParent cp=new NoConstionParent();
		cp.setContent(content);
		cp.setHeight(height);
		cp.setWeight(width);
		cp.setAbduction(abduction);
		cp.setFingerSpan(fingerSpan);
		cp.setSingForward(singForward);
		cp.setRoundTrip(roundTrip);
		cp.setCourtSprint(courtSprint);
		cp.setRestrtedArea(restrtedArea);
		cp.setKlingWing(klingWing);
		cp.setVerticalJump(verticalJump);
		cp.setContinJump(continJump);
		cp.setCreateTime(LocalDateTime.now());
		cp.setUpdateTime(LocalDateTime.now());
		int index=-1;
		try {
			  index=noConstionParentMapper.insert(cp);
			  return index>0?RespontDateJson.ok(index, "添加成功！"):RespontDateJson.fuall(index, "添加失败，服务器异常") ;
		} catch (Exception e) {
			return RespontDateJson.fuall(index, "添加失败，服务器异常")  ;
		}
	}
}
